//
// Created by hanweiguang on 2019-02-18.
// Copyright (c) 2019 hanweiguang. All rights reserved.
//

#import "MyCell.h"
#import "UIColor+extension.h"
#import "View+MASShorthandAdditions.h"

@interface MyCell ()

@property(nonatomic, strong) NSMutableArray *imgArray;//item 图片
@property(nonatomic, strong) NSMutableArray *titleArray;//item 标题

@end

@implementation MyCell {

}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier {


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initDataList];
        [self createView];
//        self.backgroundColor = [UIColor colorWithHexString:@"229922"];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

#pragma mark   初始化数据

- (void)initDataList {
    _imgArray = [@[@"mine_store", @"mine_gift", @"mine_address", @"mine_aftersale", @"mine_msg", @"mine_set"] mutableCopy];
    _titleArray = [@[@"积分商城", @"礼品中心", @"收货地址", @"售后服务", @"在线客服", @"设置"] mutableCopy];

}


- (void)createView {
    UIView *selfView = self.contentView;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            UIView *item = [[UIView alloc] init];
            UILabel *tipL = [[UILabel alloc] init];
            tipL.text = self.titleArray[(NSUInteger) (j + i * 3)];
            tipL.textColor = [UIColor colorWithHexString:@"0000ff"];
            tipL.textAlignment = NSTextAlignmentCenter;
            [item addSubview:tipL];

            UIImageView *tipImg = [[UIImageView alloc] init];
            NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"image_aa" ofType:@"png"];
            tipImg.image = [UIImage imageWithContentsOfFile:imagePath];

            [item addSubview:tipImg];

            [self.contentView addSubview:item]; //添加外层View


            [self i:i selfView:selfView j:j item:item tipL:tipL tipImg:tipImg];

            selfView = item;
        }

    }
}


- (void)i:(int)i selfView:(UIView *)selfView j:(int)j item:(UIView *)item tipL:(UILabel *)tipL tipImg:(UIImageView *)tipImg {
//为View 设置布局
    [item mas_makeConstraints:^(MASConstraintMaker *make) {  //外层view宽度三等分]
        if (i == 0) {
            make.top.equalTo(self.contentView);
        } else {
            make.top.equalTo(100);
        }
        if (j == 0) {
            make.left.mas_equalTo(self.contentView);
        } else {
            make.left.mas_equalTo(selfView.right);
        }
        make.width.equalTo(ScreenW / 3);
        make.height.equalTo(100);
    }];
    if (j == 0 && i == 1) {
        item.backgroundColor = [UIColor colorWithHexString:@"ff2211"];
    }

    [tipImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(item.center);
        make.width.and.height.equalTo(40);
    }];
    [tipL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipImg.bottom);
        make.centerX.equalTo(tipImg.centerX);
    }];
}


@end